//
//  LZToolView.m
//  ShellWallert
//
//  Created by lvzhao on 2019/5/15.
//  Copyright © 2019 吕VV. All rights reserved.
//

#import "LZToolView.h"
#import "UIButton+SGImagePosition.h"
#import "YN_PassWordView.h"
#import "PICircularProgressView.h"
#import "ShellCountryDataModel.h"

@interface LZToolView ()<UIGestureRecognizerDelegate>

//背景
@property (nonatomic,strong)UIView *backgroundView; //
@property (nonatomic,copy) void(^cancelBlock) (id object);
@property (nonatomic,copy) void(^sureBlock)(id object);
@property (nonatomic,strong) UIButton *sureBtn;
@property (nonatomic,strong) UIButton *cancelBtn;

@property (nonatomic,strong) NSDictionary *dictionary;
@property (nonatomic,copy)NSString *title;
@property (nonatomic,copy)NSString *message;
@property (nonatomic,copy)NSString *cancel;
@property (nonatomic,copy)NSString *sure;





//倒计时
@property (nonatomic, assign) NSInteger timeCount;
//取消订阅RAC信号
@property (nonatomic,strong) RACDisposable *disposable;

@property (nonatomic,strong) PICircularProgressView *progressView;
@property (nonatomic,strong) UIButton *timeBtn;

@end


@implementation LZToolView
- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    LZLog(@"LZToolView");
    if(self.disposable) {
        //释放定时器
        [self.disposable dispose];
        self.disposable = nil;
    }
    
}

//系统alert
+ (void)systemAlterType:(LZAlertViewType)alertType alterTitle:(NSString *)title message:(NSString *)message cancel:(NSString *)cancel sure:(NSString *)sure objectDict:(NSDictionary *)dictionary cancelBlock:(void(^)(id object))cancelBlock sureBlock:(void(^)(id object))sureBlock{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:(alertType == LZAlertViewTypeSystemAlter) ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
    if(cancel){
        UIAlertAction * cancelAction = nil;
        
        
        if (alertType == LZAlertViewTypeSystemAlertController) {
            cancelAction = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
                if(cancelBlock){
                    cancelBlock(nil);
                };
            }];
            
        } else {
            cancelAction = [UIAlertAction actionWithTitle:cancel style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                
                if(cancelBlock){
                    cancelBlock(nil);
                };
            }];
        }
        [alert addAction:cancelAction];
    };
    if(sure){
        UIAlertAction * sureAction = [UIAlertAction actionWithTitle:sure style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            action.enabled = NO;
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                action.enabled = YES;
            });
            if(sureBlock){
                sureBlock(nil);
            }
            
        }];
        
        [alert addAction:sureAction];
    }
    NSArray *subTitles = dictionary[@"subTitles"];
    for (NSString * title in subTitles){
        
        UIAlertAction * action = [UIAlertAction actionWithTitle:title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            if(sureBlock){
                sureBlock(@([subTitles indexOfObject:title]));
            }
        }];
        [alert addAction:action];
    }
    UIViewController *topVC = LZTool.currentViewController;
    topVC.modalPresentationStyle = UIModalPresentationFullScreen;
    [topVC presentViewController:alert animated:YES completion:nil];
}

+ (void)showAlertType:(LZAlertViewType)alertType withTitle:(NSString *__nullable)title message:(NSString *__nullable)message cancel:(NSString *__nullable)cancel sure:(NSString *__nullable)sure objectDict:(NSDictionary *__nullable)dictionary cancelBlock:(void(^)(id object))cancelBlock sureBlock:(void(^)(id object))sureBlock{
    switch (alertType) {
        case LZAlertViewTypeSystemAlter:{
            //系统的alter
            [self systemAlterType:alertType alterTitle:title message:message cancel:cancel sure:sure objectDict:dictionary cancelBlock:cancelBlock sureBlock:sureBlock];
        }
            break;
            
        default:
            [self showAlertType:alertType title:title message:message cancel:cancel sure:sure objectDict:dictionary cancelBlock:cancelBlock sureBlock:sureBlock];
            break;
    }
}



//block 回调
+ (void)showAlertType:(LZAlertViewType )alertType title:(NSString *)title message:(NSString *)message  cancel:(NSString *)cancel sure:(NSString *)sure objectDict:(NSDictionary *)dictionary  cancelBlock:(void(^)(id object))cancelBlock sureBlock:(void(^)(id object))sureBlock{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    for (UIView * aView in window.subviews) {
        if ([aView isKindOfClass:[LZToolView class]]){
            return;
        }
    }
    LZToolView *alertView = [[LZToolView alloc]initWithFrame:CGRectMake(0, 0,K_SCREENWIDTH , K_SCREENHEIGHT) alertType:alertType withTitle:title message:message cancel:cancel sure:sure objectDict:dictionary cancelBlock:cancelBlock sureBlock:sureBlock];
    [window addSubview:alertView];
    return;
}

+ (void)dismiss{
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    for (UIView * aView in window.subviews) {
        if ([aView isKindOfClass:[LZToolView class]]){
            [aView removeFromSuperview];
        }
    }
}


#pragma mark - 取消
- (void)dismissAnimate:(BOOL)animate{
    
    if(self.disposable) {
        //释放定时器
        [self.disposable dispose];
        self.disposable = nil;
    }
    
    if(animate){
        [UIView animateWithDuration:0.3 animations:^{
            self.backgroundView.frame = CGRectMake(self.backgroundView.x, K_SCREENHEIGHT, self.backgroundView.width, self.backgroundView.height);
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    } else {
        [UIView animateWithDuration:0.2 animations:^{
            self.hidden = YES;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }

}

//手势
- (void)gestureRecognizerDismiss{
    [self dismissAnimate:YES];
}

- (void)dismiss{
    [self dismissAnimate:NO];
}

#pragma mark - 增加键盘的通知
- (void)addKeyboardWillNotification
{
    @weakify(self);
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillShowNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        NSDictionary *userInfo = x.userInfo;
        NSValue *value = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
        CGRect keyboardRect = [value CGRectValue];
        
        [UIView animateWithDuration:0.4 animations:^{
            self.backgroundView.y = K_SCREENHEIGHT - keyboardRect.size.height -  self.backgroundView.height - 10;
        } completion:^(BOOL finished) {
            
        }];
    }];
    
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillHideNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        @strongify(self);
        self.backgroundView.y = (K_SCREENHEIGHT -  self.backgroundView.height )/2.0;
    }];
}




///block 回调 AlertView
- (id)initWithFrame:(CGRect)frame alertType:(LZAlertViewType)alertType withTitle:(NSString *)title message:(NSString *)message  cancel:(NSString *)cancel sure:(NSString *)sure objectDict:(NSDictionary *)dictionary cancelBlock:(void(^)(id object))cancelBlock sureBlock:(void(^)(id object))sureBlock{
    
    self = [super initWithFrame:frame];
    if(self){
        self.backgroundColor = [UIColorHex(0x000000) colorWithAlphaComponent:0.5];
        self.cancelBlock = cancelBlock;
        self.sureBlock = sureBlock;
        self.dictionary = dictionary;
        self.title = title;
        self.message = message;
        self.cancel = cancel;
        self.sure = sure;
        [self setupView];


        switch (alertType) {
            case LZAlertViewTypeActionSheet:
            {
                [self initSubActionSheetView];
            }
                break;
            case LZAlertViewTypeLiquidation:
            {
                [self initSubLiquidationView];
            }
                break;
            case LZAlertViewTypeTipAlter:
            {
                [self initSubTipAlterView];
            }
                break;
            case LZAlertViewTypeTradePassword:
            {
                [self initSubTradePasswordView];
            }
                break;
            case LZAlertViewTypTipDetail:
            {
                [self initSubTipDetailView];
            }
                break;
            case LZAlertViewTypeGrabOrder:
            {
                [self initSubGrabOrderView];
            }
                break;
            case LZAlertViewTypContinentDetail:
            {
                 [self initSubContinentView];
            }
                break;
            case LZAlertViewTypMapDetail:
            {
                 [self initSubMapDetailView];
            }
                break;
           case LZAlertViewTypPledgeTime:
            {
                [self initSubPledgeTimeView];
                
            }
                
                break;
                
            case LZAlertViewTypeSubscribe:
            {
                [self initSubSubscribeView];
            }
                           
                break;
            default:
                break;
        }

        
        
    }
    return self;
}
#pragma mark - setupView
- (void) setupView{
    self.backgroundView = [[UIView alloc]init];
    self.backgroundView.backgroundColor = UIColorHex(0x273248);
    self.backgroundView.frame = CGRectZero;
    [self addSubview:self.backgroundView];
    self.backgroundView.layer.cornerRadius = 7;
    self.backgroundView.clipsToBounds = YES;
    
    //确定
    UIButton *sureBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    sureBtn.titleLabel.font = k_textBoldFont(16);
    [sureBtn setTitle:self.sure forState:UIControlStateNormal];
    [sureBtn setTitleColor:COLOR_TINT forState:UIControlStateNormal];
    self.sureBtn = sureBtn;
    [self.backgroundView addSubview:sureBtn];
    
    //取消
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelBtn.titleLabel.font = k_textFont(16);
    [cancelBtn setTitle:self.cancel forState:UIControlStateNormal];
    [cancelBtn setTitleColor:COLOR_TINT forState:UIControlStateNormal];
    self.cancelBtn = cancelBtn;
    [self.backgroundView addSubview:cancelBtn];
    
}

#pragma mark - LZAlertViewTypeSubscribe
- (void) initSubSubscribeView{

    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 8;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.centerX.mas_equalTo(self.mas_centerX);
       make.width.mas_offset(K_SCREENWIDTH - 70);
       make.height.mas_equalTo(310);
       make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(18);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-35);
        make.height.mas_equalTo(25);
    }];
    

    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(14);
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.numberOfLines = 0;
    [messageLabel lz_centerAlignment];
    messageLabel.text = self.message;
    [self.backgroundView addSubview:messageLabel];
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 140];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(22);
        make.left.mas_equalTo(35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(messageHeight);
    }];
    
    ///!!!:textField
    UITextField *textField = [[UITextField alloc] init];
    textField.bColor = UIColorHex(0x11385E);
    textField.keyboardType = UIKeyboardTypeDecimalPad;
    textField.bWidth = 0.5;
    textField.placeholder = self.dictionary[@"placeholder"];
    textField.cornerRadius = 8;
    [self.backgroundView addSubview:textField];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(messageLabel.mas_bottom).mas_offset(8);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(K_SCREENWIDTH - 110);
        make.height.mas_equalTo(38);
    }];
    
    UIView *leftView = [[UIView alloc] init];
    leftView.frame = CGRectMake(0, 0, 25, 25);
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeAlways;
    
    
    
    ///!!!:资金密码
    UILabel *assestPasswordLab = [UILabel lz_labelWithText:LZLocalizedString(@"资金密码") fontSize:k_textFont(14) color:UIColorHex(0x8D99B2)];
    [assestPasswordLab lz_centerAlignment];
    [self.backgroundView addSubview:assestPasswordLab];
    [assestPasswordLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(textField.mas_bottom).mas_offset(15);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(K_SCREENWIDTH - 110);
        make.height.mas_equalTo(20);
    }];
    
    
    YN_PassWordView *codeView = [[YN_PassWordView alloc] init];
    CGFloat itemWidth = (K_SCREENWIDTH - 70 - 40 - 5 * 5)/6;
    codeView.frame = CGRectMake(20, 178, K_SCREENWIDTH - 70 - 40,itemWidth);

    [self.backgroundView addSubview:codeView];
    codeView.showType = 3;//五种样式
    codeView.num = 6;//框框个数
    codeView.tintColor = UIColorHex(0x11385E);//主题色
    [codeView show];
    
    ///!!!:取消
    CGFloat btnW = (K_SCREENWIDTH - 140 - 20) /2.0;
    self.cancelBtn .titleLabel.font = k_textFont(16);
    self.cancelBtn.backgroundColor = UIColorHex(0x0D3354);
    self.cancelBtn.cornerRadius = 20;
    [self.cancelBtn  setTitleColor:UIColorHex(0x8D99B2) forState:UIControlStateNormal];
    [self.cancelBtn  setTitle:self.cancel forState:UIControlStateNormal];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(35);
        make.bottom.mas_equalTo(-20);
        make.width.mas_equalTo(btnW);
        make.height.mas_equalTo(40);
    }];
    @weakify(self);
    [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.cancelBlock){
            self.cancelBlock(@"");
        }
        [self dismissAnimate:NO];
    }];
    
    
    ///!!!:确定
    self.cancelBtn .titleLabel.font = k_textFont(16);
    [self.sureBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.sureBtn setTitle:self.sure forState:UIControlStateNormal];
    
    UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, K_SCREENWIDTH - btnW, 40)];
    self.sureBtn.cornerRadius = 20;
    [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-35);
        make.bottom.mas_equalTo(-20);
        make.width.mas_equalTo(btnW);
        make.height.mas_equalTo(40);
    }];
    [[self.sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(@{@"password":codeView.textF.text?:@"",
                             @"number":textField.text?:@""});
        }
        [self dismissAnimate:NO];
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
    
    //键盘通知
    [self addKeyboardWillNotification];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [textField becomeFirstResponder];
    });
    
    
    

}
         


#pragma mark - LZAlertViewTypPledgeTime
- (void) initSubPledgeTimeView{

    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 8;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 70);
        make.height.mas_equalTo(255);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(14);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-35);
        make.height.mas_equalTo(20);
    }];
    
    
    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(12);
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.numberOfLines = 0;
    messageLabel.text = self.message;
    [self.backgroundView addSubview:messageLabel];
    messageLabel.textAlignment = NSTextAlignmentCenter;
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 140];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(messageHeight);
    }];
    
    [self.backgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(messageHeight + 150);
    }];
    
       ///!!!:确定
    self.sureBtn.titleLabel.font = k_textFont(17);
    [self.sureBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.sureBtn setTitle:self.sure forState:UIControlStateNormal];
    
    UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, K_SCREENWIDTH - 140, 50)];
    self.sureBtn.cornerRadius = 6;
    [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backgroundView.mas_centerX);
        make.bottom.mas_equalTo(-20);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(40);
    }];
    
    @weakify(self);
    [[self.sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(@"");
        }
        [self dismissAnimate:NO];
    }];
}
#pragma mark - LZAlertViewTypMapDetail
- (void) initSubMapDetailView{

    self.backgroundView.backgroundColor = [UIColorHex(0x4AB2E7) colorWithAlphaComponent:0.5];
    self.backgroundView.cornerRadius = 8;
    
    CGFloat backgroundViewHeight = 180;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 130);
        make.height.mas_equalTo(backgroundViewHeight);
        make.top.mas_equalTo(100);
    }];

    
    NSArray *detailModels = self.dictionary[@"continent"];
    NSMutableArray *continentArray = [[NSMutableArray alloc] initWithCapacity:0];
    for (int i = 0; i < detailModels.count; i++) {
        
        ShellCountryDataModel *dataModel = detailModels[i];
        [continentArray addObject:dataModel.name];
        [continentArray addObject:[NSString stringWithFormat:@"%ld",(long)dataModel.userCount]];

    }
    
    
    //每个Item宽高
    CGFloat H = 20;
    CGFloat btnW = (K_SCREENWIDTH - 130 - 30 - 10) / 2.0;
    //每行列数
    NSInteger rank = 2;
    //每列间距
    CGFloat rankMargin = 10;
    //每行间距
    CGFloat rowMargin = 13;
    @weakify(self)
    for(int i = 0; i < continentArray.count; i++){
        
        UIButton *continentBtn = [UIButton lz_buttonTitle:continentArray[i] titleColor:UIColorHex(0xFFFFFF)
                                                 fontSize:14];
        continentBtn.tag = 100 + i;
        [self.backgroundView addSubview:continentBtn];
        
        //Item X轴
        CGFloat X = (i % rank) * (btnW + rankMargin) + 20;
        //Item Y轴
        NSUInteger Y = (i / rank) * (H +rowMargin);
        //Item top
        CGFloat top = 11;
        
        [continentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
          make.left.mas_equalTo(X);
          make.top.mas_equalTo(Y + top);
          make.width.mas_equalTo(btnW);
          make.height.mas_equalTo(H);
        }];

        
        if(i%2 == 0){
            
            continentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        } else {
            continentBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
            [continentBtn setImage:k_imageName(@"icon_home_jiantou") forState:UIControlStateNormal];
            [continentBtn SG_imagePositionStyle:SGImagePositionStyleRight spacing:5];
        }
        
        
        [[continentBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            if(self.sureBlock){
                self.sureBlock(@(i/2));
            }
        }];
    }
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tapGesture];
}
#pragma mark - LZAlertViewTypContinentDetail
- (void) initSubContinentView{

    self.backgroundView.backgroundColor = [UIColorHex(0x4AB2E7) colorWithAlphaComponent:0.5];
    self.backgroundView.cornerRadius = 8;
    
    CGFloat backgroundViewHeight = 152;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 100);
        make.height.mas_equalTo(backgroundViewHeight);
        make.top.mas_equalTo(100);
    }];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(14);
    titleLabel.text = self.title;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(K_SCREENWIDTH - 100 - 40);
        make.height.mas_equalTo(20);
    }];
   
    ///!!!:取消
    [self.cancelBtn setImage:k_imageName(@"icon_bai_cancel") forState:UIControlStateNormal];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
       make.right.mas_equalTo(-15);
       make.top.mas_equalTo(10);
       make.width.mas_equalTo(24);
       make.height.mas_equalTo(24);
    }];
       
    @weakify(self);
    [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
       @strongify(self);
       [self dismissAnimate:NO];
    }];

    NSArray *titles = self.dictionary[@"dataArray"];
    for (int i = 0; i < titles.count; i++){
        UILabel *titleLab = [UILabel lz_labelWithText:titles[i] fontSize:k_textFont(12) color:UIColorHex(0xFFFFFF)];
        titleLab.adjustsFontSizeToFitWidth = YES;
        [self.backgroundView addSubview:titleLab];
        [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.top.mas_equalTo(i * 22 + 50);
            make.height.mas_equalTo(17);
            make.width.mas_equalTo(K_SCREENWIDTH - 100 - 40);
        }];
    }
    
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tapGesture];
    

}





#pragma mark - LZAlertViewTypeGrabOrder
- (void) initSubGrabOrderView {
    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 8;
    
    CGFloat backgroundViewHeight = 250;

    if(K_Device_Is_iPhoneX){
        backgroundViewHeight += 43;
    }
    self.backgroundView.frame = CGRectMake(0, K_SCREENHEIGHT, K_SCREENWIDTH, backgroundViewHeight);

    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(14);
    titleLabel.text = self.title;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(15);
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-100);
        make.height.mas_equalTo(20);
    }];
    
    ///!!!:取消
    [self.cancelBtn setImage:k_imageName(@"icon_cancel") forState:UIControlStateNormal];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(24);
        make.height.mas_equalTo(24);
    }];
    
    @weakify(self);
    [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self dismissAnimate:YES];
    }];
    
    
    ///!!!:金额 money
    UILabel *moneyLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(12) color:UIColorHex(0x8D99B2)];
    [self.backgroundView addSubview:moneyLab];
    [moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-150);
        make.top.mas_equalTo(93);
        make.height.mas_equalTo(20);
    }];
    
    
//                                       @"type":dataDictionary[@"type"]?:@"",
//                                       @"standardCurrency":dataDictionary[@"standardCurrency"]?:@"",
//                                       @"awardUsdt":dataDictionary[@"awardUsdt"]?:@""};
    
    
    
    NSString *moneyString = [NSString stringWithFormat:@"%@ $ %@", LZLocalizedString(@"订单金额"),self.dictionary[@"orderAmount"]];
    NSMutableAttributedString *moneyAttributedString = [NSAttributedString attributedString:moneyString rangeTitle:LZLocalizedString(@"订单金额") leftFont:k_textFont(14) rightFont:k_textFont(12) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0x8D99B2)];
    moneyLab.attributedText = moneyAttributedString;
    
    
    ///!!!:类型 type
    UILabel *typeLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(12) color:UIColorHex(0x8D99B2)];
    [self.backgroundView addSubview:typeLab];
    [typeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-150);
        make.top.mas_equalTo(moneyLab.mas_bottom).mas_offset(9);
        make.height.mas_equalTo(20);
    }];
    
    NSString *type = self.dictionary[@"type"];
    NSString *typeString = [NSString stringWithFormat:@"%@ %@", LZLocalizedString(@"订单类型"),[type isEqualToString:@"in"] ? LZLocalizedString(@"回款"):LZLocalizedString(@"支付")];
    NSMutableAttributedString *typeAttributedString = [NSAttributedString attributedString:typeString rangeTitle:LZLocalizedString(@"订单类型") leftFont:k_textFont(14) rightFont:k_textFont(12) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0x8D99B2)];
    typeLab.attributedText = typeAttributedString;
    
    
    ///!!!:币种 currency
    UILabel *currencyLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(12) color:UIColorHex(0x8D99B2)];
    [self.backgroundView addSubview:currencyLab];
    [currencyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-150);
        make.top.mas_equalTo(typeLab.mas_bottom).mas_offset(9);
        make.height.mas_equalTo(20);
    }];
    
    
    NSString *currencyString = [NSString stringWithFormat:@"%@ %@", LZLocalizedString(@"本位币种"),self.dictionary[@"standardCurrency"]];
    NSMutableAttributedString *currencyAttributedString = [NSAttributedString attributedString:currencyString rangeTitle:LZLocalizedString(@"本位币种") leftFont:k_textFont(14) rightFont:k_textFont(12) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0x8D99B2)];
    currencyLab.attributedText = currencyAttributedString;
    
    ///!!!:奖励reward
    UILabel *rewardLab = [UILabel lz_labelWithText:@"" fontSize:k_textFont(12) color:UIColorHex(0x8D99B2)];
    [self.backgroundView addSubview:rewardLab];
    [rewardLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.right.mas_equalTo(-150);
        make.top.mas_equalTo(currencyLab.mas_bottom).mas_offset(9);
        make.height.mas_equalTo(20);
    }];
    
    
    NSString *rewardString = [NSString stringWithFormat:@"%@ %@ USDT", LZLocalizedString(@"服务奖励"),self.dictionary[@"awardUsdt"]];
    NSMutableAttributedString *rewardAttributedString = [NSAttributedString attributedString:rewardString rangeTitle:LZLocalizedString(@"服务奖励") leftFont:k_textFont(14) rightFont:k_textFont(12) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0x8D99B2)];
    rewardLab.attributedText = rewardAttributedString;
    
    ///!!!:倒计时
    [self.backgroundView addSubview:self.progressView];
    self.progressView.progress = 1;
    [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-25);
        make.width.height.mas_equalTo(100);
        make.top.mas_equalTo(100);
    }];


    [self.backgroundView addSubview:self.timeBtn];
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.progressView.mas_centerY);
        make.width.height.mas_equalTo(70);
        make.centerX.mas_equalTo(self.progressView.mas_centerX);
    }];
    
    
    self.timeCount = 15;
    NSString *timeString = [NSString stringWithFormat:@"%@\n%ldS", LZLocalizedString(@"抢单"),self.timeCount];
    NSMutableAttributedString *timeAttributedString = [NSAttributedString attributedString:timeString rangeTitle:LZLocalizedString(@"抢单") leftFont:k_textFont(12) rightFont:k_textFont(18) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0xFFFFFF)];
    NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
    paragraph.alignment = NSTextAlignmentCenter;
    [timeAttributedString addAttributes:@{NSParagraphStyleAttributeName:paragraph} range:NSMakeRange(0, timeString.length)];
    [self.timeBtn setAttributedTitle:timeAttributedString forState:UIControlStateNormal];
    
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.backgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    //设置大小
    maskLayer.frame = self.backgroundView.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.backgroundView.layer.mask = maskLayer;
    
    [UIView animateWithDuration:0.2 animations:^{
        self.backgroundView.frame = CGRectMake(0, K_SCREENHEIGHT - self.backgroundView.height, K_SCREENWIDTH,  self.backgroundView.height);
    } completion:^(BOOL finished) {
        
    }];
    
    self.disposable = [[RACSignal interval:1.0 onScheduler:[RACScheduler mainThreadScheduler]]subscribeNext:^(NSDate * _Nullable x) {
        @strongify(self)
        
        self.timeCount -- ;
        if(self.timeCount < 1){
            self.timeCount  = 0;
            [self.disposable dispose];
            self.disposable = nil;
            [self dismissAnimate:YES];
        }
        //设置文字
        NSString *timeString = [NSString stringWithFormat:@"%@\n%ldS", LZLocalizedString(@"抢单"),self.timeCount];
        NSMutableAttributedString *timeAttributedString = [NSAttributedString attributedString:timeString rangeTitle:LZLocalizedString(@"抢单") leftFont:k_textFont(12) rightFont:k_textFont(18) leftColor:UIColorHex(0xFFFFFF) rightColor:UIColorHex(0xFFFFFF)];
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.alignment = NSTextAlignmentCenter;
        [timeAttributedString addAttributes:@{NSParagraphStyleAttributeName:paragraph} range:NSMakeRange(0, timeString.length)];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            @strongify(self)
            [self.timeBtn setAttributedTitle:timeAttributedString forState:UIControlStateNormal];
            self.progressView.progress = self.timeCount / 15.0;
        });
    }];
    

    [[self.timeBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(@"");
        }
    }];
    
}

- (PICircularProgressView *)progressView{
    if(!_progressView){
        _progressView = [[PICircularProgressView alloc] init];
    }
    return _progressView;
}


- (UIButton *)timeBtn{
    if(!_timeBtn){
        _timeBtn = [UIButton lz_buttonTitle:@"" titleColor:UIColorHex(0xFFFFFF) fontSize:18];
        _timeBtn.backgroundColor = UIColorHex(0x4AB2E7);
        _timeBtn.cornerRadius = 35;
        _timeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _timeBtn.titleLabel.numberOfLines = 0;
    }
    return _timeBtn;
}



#pragma mark - LZAlertViewTypTipDetail
- (void) initSubTipDetailView {
    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 8;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 70);
        make.height.mas_equalTo(255);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(14);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-35);
        make.height.mas_equalTo(20);
    }];
    
   
    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(12);
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.numberOfLines = 0;
    messageLabel.text = self.message;
    [self.backgroundView addSubview:messageLabel];
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 140];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(messageHeight);
    }];
    
    [self.backgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(messageHeight + 100);
    }];
    
    ///!!!:取消
    [self.cancelBtn setImage:k_imageName(@"icon_cancel") forState:UIControlStateNormal];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.top.mas_equalTo(10);
        make.width.mas_equalTo(24);
        make.height.mas_equalTo(24);
    }];
    
    @weakify(self);
    [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        [self dismissAnimate:NO];
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tapGesture];
    
}
#pragma mark - LZAlertViewTypeTradePassword
- (void) initSubTradePasswordView {
    
    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 6;
    self.backgroundView.frame = CGRectMake(35, (K_SCREENHEIGHT - 225) / 2.0, K_SCREENWIDTH - 70, 225);
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 70);
        make.height.mas_equalTo(255);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];

    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(18);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-35);
        make.height.mas_equalTo(25);
    }];
    

    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(14);
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.numberOfLines = 0;
    [messageLabel lz_centerAlignment];
    messageLabel.text = self.message;
    [self.backgroundView addSubview:messageLabel];
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 140];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(15);
        make.left.mas_equalTo(35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(messageHeight);
    }];
    
    
    
    YN_PassWordView *codeView = [[YN_PassWordView alloc] init];
    CGFloat itemWidth = (K_SCREENWIDTH - 70 - 40 - 5 * 5)/6;
    codeView.frame = CGRectMake(20, 110, K_SCREENWIDTH - 70 - 40,itemWidth);

    [self.backgroundView addSubview:codeView];
    codeView.showType = 3;//五种样式
    codeView.num = 6;//框框个数
    codeView.tintColor = UIColorHex(0x11385E);//主题色
    [codeView show];
    
    ///!!!:取消
    CGFloat btnW = (K_SCREENWIDTH - 140 - 20) /2.0;
    self.cancelBtn .titleLabel.font = k_textFont(16);
    self.cancelBtn.backgroundColor = UIColorHex(0x0D3354);
    self.cancelBtn.cornerRadius = 20;
    [self.cancelBtn  setTitleColor:UIColorHex(0x8D99B2) forState:UIControlStateNormal];
    [self.cancelBtn  setTitle:self.cancel forState:UIControlStateNormal];
    [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(35);
        make.bottom.mas_equalTo(-20);
        make.width.mas_equalTo(btnW);
        make.height.mas_equalTo(40);
    }];
    @weakify(self);
    [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.cancelBlock){
            self.cancelBlock(@"");
        }
        [self dismissAnimate:NO];
    }];
    
    
    ///!!!:确定
    self.cancelBtn .titleLabel.font = k_textFont(16);
    [self.sureBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.sureBtn setTitle:self.sure forState:UIControlStateNormal];
    
    UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, K_SCREENWIDTH - btnW, 40)];
    self.sureBtn.cornerRadius = 20;
    [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-35);
        make.bottom.mas_equalTo(-20);
        make.width.mas_equalTo(btnW);
        make.height.mas_equalTo(40);
    }];
    [[self.sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(codeView.textF.text);
        }
        [self dismissAnimate:NO];
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    tapGesture.delegate = self;
    [self addGestureRecognizer:tapGesture];
    
    //键盘通知
    [self addKeyboardWillNotification];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [codeView.textF becomeFirstResponder];
    });
    
}






#pragma mark - LZAlertViewTypeTipAlter
- (void) initSubTipAlterView {
    
    
    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 6;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 70);
        make.height.mas_equalTo(255);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(16);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0xFFFFFF);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(30);
        make.left.mas_equalTo(35);
        make.right.mas_equalTo(-35);
        make.height.mas_equalTo(20);
    }];
    
    
    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(14);
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.numberOfLines = 0;
    messageLabel.text = self.message;
    
    if (self.dictionary[@"textAlignment"]) {
        NSTextAlignment messageAlignment = [self.dictionary[@"textAlignment"] intValue];
        messageLabel.textAlignment = messageAlignment;
    }
    [self.backgroundView addSubview:messageLabel];
    CGFloat messageHeight = [messageLabel.text lz_textHeightWithFontSize:messageLabel.font withMaxWidth:K_SCREENWIDTH - 140];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(20);
        make.width.mas_equalTo(K_SCREENWIDTH - 110);
        make.height.mas_equalTo(messageHeight);
    }];
    
    [self.backgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(messageHeight + 150);
    }];
    
    ///!!!:确定
    self.sureBtn.titleLabel.font = k_textFont(17);
    [self.sureBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.sureBtn setTitle:self.sure forState:UIControlStateNormal];
    
    UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, K_SCREENWIDTH - 140, 50)];
    self.sureBtn.cornerRadius = 6;
    [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backgroundView.mas_centerX);
        make.bottom.mas_equalTo(-30);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(40);
    }];
    

    @weakify(self);
    [[self.sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(@"");
        }
        [self dismissAnimate:NO];
    }];
    
    
    if(self.cancel.length > 0){
        
        self.cancelBtn.titleLabel.font = k_textFont(17);
        [self.cancelBtn setTitleColor:UIColorHex(0x8D99B2) forState:UIControlStateNormal];
        [self.cancelBtn setTitle:self.cancel forState:UIControlStateNormal];
        self.cancelBtn.backgroundColor = UIColorHex(0x0D3354);
        self.cancelBtn.cornerRadius = 6;
        [self.cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.bottom.mas_equalTo(-20);
            make.width.mas_equalTo((K_SCREENWIDTH - 150)/2.0);
            make.height.mas_equalTo(50);
        }];
             
        UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, (K_SCREENWIDTH - 150)/2.0, 50)];
        [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
        [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-20);
            make.bottom.mas_equalTo(-20);
            make.width.mas_equalTo((K_SCREENWIDTH - 150)/2.0);
            make.height.mas_equalTo(50);
        }];
        
        [[self.cancelBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self);
            [self dismissAnimate:NO];
        }];
        
    }
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tapGesture];
}



#pragma mark - LZAlertViewTypeLiquidation
- (void) initSubLiquidationView {
    

    CGFloat messageHeight = [self.message lz_textHeightWithFontSize:k_textFont(12) withMaxWidth:K_SCREENWIDTH - 140];
    self.backgroundView.backgroundColor = COLOR_TINT;
    self.backgroundView.cornerRadius = 5;
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.width.mas_offset(K_SCREENWIDTH - 70);
        make.height.mas_equalTo(messageHeight + 250);
        make.centerY.mas_equalTo(self.mas_centerY);
    }];
    
    UIImageView *successImgView = [[UIImageView alloc] init];
    successImgView.image = k_imageName(@"ico_sucessed");
    [self.backgroundView addSubview:successImgView];
    [successImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backgroundView.mas_centerX);
        make.top.mas_equalTo(40);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    

    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = k_textBoldFont(14);
    titleLabel.text = self.title;
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.textColor = UIColorHex(0x64E3AE);
    [self.backgroundView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(successImgView.mas_bottom).mas_offset(13);
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(20);
    }];
    
    ///!!!:message
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.font = k_textFont(12);
    messageLabel.numberOfLines = 0;
    messageLabel.text = self.message;
    messageLabel.textColor = UIColorHex(0x8D99B2);
    messageLabel.textAlignment = NSTextAlignmentCenter;
    [self.backgroundView addSubview:messageLabel];
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(titleLabel.mas_bottom).mas_offset(10);
        make.left.mas_equalTo(35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(messageHeight);
    }];
    
    ///!!!:确定
    self.sureBtn.titleLabel.font = k_textFont(17);
    [self.sureBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
    [self.sureBtn setTitle:self.sure forState:UIControlStateNormal];
    
    UIImage *highlightImage = [UIImage gradientImageWithColors:@[UIColorHex(0x65DFFE),UIColorHex(0x2C6FE)] rect:CGRectMake(0, 0, K_SCREENWIDTH - 140, 50)];
    self.sureBtn.cornerRadius = 6;
    [self.sureBtn setBackgroundImage:highlightImage forState:UIControlStateNormal];
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.backgroundView.mas_centerX);
        make.bottom.mas_equalTo(-35);
        make.width.mas_equalTo(K_SCREENWIDTH - 140);
        make.height.mas_equalTo(40);
    }];
    
    @weakify(self);
    [[self.sureBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        if(self.sureBlock){
            self.sureBlock(@"");
        }
        [self dismissAnimate:NO];
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
    [self addGestureRecognizer:tapGesture];
}

#pragma mark - LZAlertViewTypeActionSheet
- (void) initSubActionSheetView {
    
    CGFloat btnHeight = 55;
    self.backgroundView.cornerRadius = 0;
    NSMutableArray *titles = [[NSMutableArray alloc] initWithArray:self.dictionary[@"subtitles"]];
    self.backgroundView.frame = CGRectMake(0, K_SCREENHEIGHT, K_SCREENWIDTH, btnHeight * titles.count);
    self.backgroundView.backgroundColor = UIColorHex(0x031D32);
    BOOL isTitle = NO;
    if(self.title.length > 0){
        isTitle = YES;
        self.backgroundView.height += btnHeight;
        [titles insertObject:self.title atIndex:0];
    }
    if(K_Device_Is_iPhoneX){
        self.backgroundView.height += 43;
    }
    
    
    for(int i = 0; i < titles.count; i++){
        
        UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.backgroundColor = UIColorHex(0x031D32);
        button.adjustsImageWhenHighlighted = NO;
        button.frame = CGRectMake(0, (i == titles.count - 1) ? btnHeight * i : btnHeight * i ,K_SCREENWIDTH, btnHeight);
        [button setTitle:titles[i] forState:UIControlStateNormal];
        [button setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
        button.tag = 1000 + i;
        button.titleLabel.font = k_textFont(16);
        
        if (i != titles.count - 1) {
            UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, btnHeight - 0.5, K_SCREENWIDTH, 0.5)];
            lineView.backgroundColor = RGBA(143, 149, 170, 0.16);
            [button addSubview:lineView];
        }
        
        if([titles[i] isEqualToString:self.message]){
            button.selected = YES;
            button.titleLabel.font = k_textBoldFont(16);
        }
        
        if(i == 0){
            
            UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
            CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
            //设置大小
            maskLayer.frame = button.bounds;
            //设置图形样子
            maskLayer.path = maskPath.CGPath;
            button.layer.mask = maskLayer;
            
            if(isTitle){
                button.titleLabel.font = k_textBoldFont(18);
                button.userInteractionEnabled = NO;
            }
        }
        
        
        if(i == titles.count - 1){
            button.titleLabel.font = k_textBoldFont(16);
        }
        
        [self.backgroundView addSubview:button];
        
        @weakify(self)
        [[button rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
            @strongify(self)
            if(self.sureBlock){
                if (i == titles.count - 1) {
                    [self dismissAnimate:YES];
                } else {
                    self.sureBlock(@(button.tag - 1000 - (isTitle? 1 : 0)));
                    [self dismissAnimate:YES];
                }
            }
        }];
    }
    
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.backgroundView.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    //设置大小
    maskLayer.frame = self.backgroundView.bounds;
    //设置图形样子
    maskLayer.path = maskPath.CGPath;
    self.backgroundView.layer.mask = maskLayer;
    
    
    [UIView animateWithDuration:0.2 animations:^{
        self.backgroundView.frame = CGRectMake(0, K_SCREENHEIGHT - self.backgroundView.height, K_SCREENWIDTH,  self.backgroundView.height);
    } completion:^(BOOL finished) {
        
    }];
    
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gestureRecognizerDismiss)];
    [self addGestureRecognizer:tapGesture];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self endEditing:YES];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{

    
    //如果是子视图 self ，设置无法接受 父视图 点击事件。
    if (touch.view == self) {
        return YES;
    }
    
    return NO;
    
}



@end
